<%--
  Created by IntelliJ IDEA.
  User: L
  Date: 2021/4/6
  Time: 11:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>ajax根据省份id获取名称</title>
    <script type="text/javascript">
      function search(){
        var xmlHttp = new XMLHttpRequest();
        xmlHttp.onreadystatechange = function(){
          if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
            var strJson = xmlHttp.responseText;
            eval("var json="+strJson);
            callback(json);
          }
        };
        var proId = document.getElementById("proid").value;

        xmlHttp.open("get","queryJson?proid="+proId,true);
        xmlHttp.send();
        function callback(json){
          document.getElementById("proname").value = json.name;
          document.getElementById("projiancheng").value = json.jiancheng;
          document.getElementById("proshenghui").value = json.shenghui;
        }

      }
    </script>
  </head>
  <body>
    <table>
      <tr>
        <td>省份编号：</td>
        <td>
          <input type="text" id="proid">
          <input type="button" value="搜索" onclick="search()">
        </td>
      </tr>
      <tr>
        <td>省份名称: </td>
        <td><input type="text" id="proname"></td>
      </tr>
      <tr>
        <td>省份简称: </td>
        <td><input type="text" id="projiancheng"></td>
      </tr>
      <tr>
        <td>省会名称: </td>
        <td><input type="text" id="proshenghui"></td>
      </tr>
    </table>
  </body>
</html>
